﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Data;
using System.Data.SqlClient;
using Support.DTO;

namespace DataAccess
{
    public class OsteoMuscularDAL : BaseSQLDAL
    {
        public int GuardarOsteoMuscular(OsteoMuscularDTO osteo)
        {
            try
            {
                CreateCommand("OsteoMuscular_Guardar", true);
                AddCmdParameter("@ColumnaCervical", string.IsNullOrEmpty(osteo.Cervical) ? "" : osteo.Cervical, ParameterDirection.Input);
                AddCmdParameter("@Dorsal", string.IsNullOrEmpty(osteo.Dorsal) ? "" : osteo.Dorsal, ParameterDirection.Input);
                AddCmdParameter("@Lumbar", string.IsNullOrEmpty(osteo.Lumbar) ? "" : osteo.Lumbar, ParameterDirection.Input);
                AddCmdParameter("@Movilidad", string.IsNullOrEmpty(osteo.Movilidad) ? "" : osteo.Movilidad, ParameterDirection.Input);
                AddCmdParameter("@Dolor", string.IsNullOrEmpty(osteo.Dolor) ? "" : osteo.Dolor, ParameterDirection.Input);
                AddCmdParameter("@Tumefaccion", string.IsNullOrEmpty(osteo.Tumefaccion) ? "" : osteo.Tumefaccion, ParameterDirection.Input);
                AddCmdParameter("@HistoriaId", osteo.HistoriaId, ParameterDirection.Input);

                ExecuteReader();
                Read();

                return Convert.ToInt32(GetOutResult("osteoMuscular_id"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                //DisposeDataReader();
                CloseConnection();
            }
        }

        public void Modificar(OsteoMuscularDTO osteo)
        {
            try
            {
                CreateCommand("OsteoMuscular_Modificar", true);
                AddCmdParameter("@ColumnaCervical", string.IsNullOrEmpty(osteo.Cervical) ? "" : osteo.Cervical, ParameterDirection.Input);
                AddCmdParameter("@Dorsal", string.IsNullOrEmpty(osteo.Dorsal) ? "" : osteo.Dorsal, ParameterDirection.Input);
                AddCmdParameter("@Lumbar", string.IsNullOrEmpty(osteo.Lumbar) ? "" : osteo.Lumbar, ParameterDirection.Input);
                AddCmdParameter("@Movilidad", string.IsNullOrEmpty(osteo.Movilidad) ? "" : osteo.Movilidad, ParameterDirection.Input);
                AddCmdParameter("@Dolor", string.IsNullOrEmpty(osteo.Dolor) ? "" : osteo.Dolor, ParameterDirection.Input);
                AddCmdParameter("@Tumefaccion", string.IsNullOrEmpty(osteo.Tumefaccion) ? "" : osteo.Tumefaccion, ParameterDirection.Input);
                AddCmdParameter("@HistoriaId", osteo.HistoriaId, ParameterDirection.Input);

                ExecuteReader();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                //DisposeDataReader();
                CloseConnection();
            }
        }

        public void Eliminar(int historiaId)
        {
            try
            {
                CreateCommand("OsteoMuscular_Eliminar", true);
                AddCmdParameter("@HistoriaId", historiaId, ParameterDirection.Input);

                ExecuteReader();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                //DisposeDataReader();
                CloseConnection();
            }
        }
    }
}
